package com.ruoyi.APPMS.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.APPMS.domain.Salesperson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Salepartorder;
import com.ruoyi.APPMS.service.ISalepartorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部件销售订单Controller
 *
 * @author 谢雨琦
 * @date 2023-07-04
 */
@Api(tags="部件销售订单控制器")
@RestController
@RequestMapping("/salepartorder/salepartorder")
public class SalepartorderController extends BaseController
{
    @Autowired
    private ISalepartorderService salepartorderService;

    /**
     * 查询部件销售订单列表
     */
    @ApiOperation("分页查询部件销售订单列表")
    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Salepartorder salepartorder)
    {
        startPage();
        List<Salepartorder> list = salepartorderService.list(salepartorder);
        return getDataTable(list);
    }

    /**
     * 导出部件销售订单列表
     */
    @ApiOperation("导出部件销售订单列表")
    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:export')")
    @Log(title = "部件销售订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Salepartorder salepartorder)
    {

        List<Salepartorder> list = salepartorderService.list(salepartorder);
        ExcelUtil<Salepartorder> util = new ExcelUtil<Salepartorder>(Salepartorder.class);
        util.exportExcel(response, list, "部件销售订单数据");
    }

    /**
     * 获取部件销售订单详细信息
     */
    @ApiOperation("获取部件销售订单详细信息")
    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:query')")
    @GetMapping(value = "/{salepartorderid}")
    public AjaxResult getInfo(@PathVariable("salepartorderid") Long salepartorderid)
    {
        return success(salepartorderService.getById(salepartorderid));
    }

//    /**
//     * 新增部件销售订单
//     */
//    @ApiOperation("新增部件销售订单")
//    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:add')")
//    @Log(title = "部件销售订单", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody Salepartorder salepartorder)
//    {
//        return toAjax(salepartorderService.save(salepartorder));
//    }

    /**
     * 修改（发货）部件销售订单
     */
    @ApiOperation("部件销售发货功能")
    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:edit')")
    @Log(title = "部件销售订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Salepartorder salepartorder)
    {
        return toAjax(salepartorderService.edit(salepartorder)&&salepartorderService.edit2(salepartorder)&&salepartorderService.edit3(salepartorder));
    }

    /**
     * 删除部件销售订单
     */
    @ApiOperation("删除部件销售订单")
    @PreAuthorize("@ss.hasPermi('salepartorder:salepartorder:remove')")
    @Log(title = "部件销售订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{salepartorderids}")
    public AjaxResult remove(@PathVariable List<Long> salepartorderids)
    {
        return toAjax(salepartorderService.removeByIds(salepartorderids));
    }
}
